package com.alili_tv.system.mapper;

import com.alili_tv.system.entity.Video;
import org.apache.ibatis.annotations.MapKey;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public interface BaseDaoMapper<T> {

    /**
     * 通过ids获取，返回以key为id的map
     * select *
     * from user
     * where id
     * in (
     * <foreach collection="ids" item="item" separator=",">
     *     #{item}
     * </foreach>
     * )
     * @param ids
     * @return
     */
    @MapKey("id")
    Map<Long, T> getByIds(Collection<Long> ids);

    /**
     * 通过ids获取, 并按照in的顺序排序
     * select *
     * from video
     * where id
     * in (
     * <foreach item="item" collection="ids" separator=",">
     *     #{item}
     * </foreach>
     * )
     * order by
     * field(id,
     *     <foreach collection="ids" separator="," item="item">
     *         #{item}
     *     </foreach>
     * )
     * @param ids
     * @return
     */
    List<T> getOrderByIn(Collection<Long> ids);
}
